#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <set>
using namespace std;
class Solution
{
public:
    vector<vector<int>> ans;
    vector<int> slice;
    void dfs(vector<int> &nums, vector<bool> &used, int cur)
    {
        if (cur > nums.size())
            return;
        ans.push_back(slice);
        for (int i = cur, flag = false; i < nums.size(); ++i)
        {
            if (i > 0)
            {
                flag = true;
                for (int j = 0; j < i; ++j)
                {
                    if (nums[j] == nums[i] && used[j] == false)
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag == false)
                    continue;
            }
            used[i] = true;
            slice.push_back(nums[i]);
            dfs(nums, used, i + 1);
            used[i] = false;
            slice.pop_back();
        }
    }
    vector<vector<int>> subsetsWithDup(vector<int> &nums)
    {
        vector<bool> used(nums.size(), false);
        dfs(nums, used, 0);
        return ans;
    }
};